package com.example.x264cameraxpush;

import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.view.PreviewView;

import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    LivePush livePush;
    volatile  boolean isFirst= true;
    volatile  boolean isStart= true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


      PreviewView previewView =  findViewById(R.id.previewView);
        livePush = new LivePush();
        livePush.native_init();
        CameraXHelper cameraXHelper = new CameraXHelper(this, 720, 1280, previewView);
        cameraXHelper.setCallBack(new CameraXHelper.ICallBack() {
            @Override
            public void call(byte[] data, Size size) {
                if (isFirst) {
                    isFirst = false;
                    livePush.native_setVideoInfo(size.getWidth(),size.getHeight(),15,640_000);
                }
                livePush.native_pushVideo(data);
            }
        });
    }

    public void startLive(View view) {
        Log.e("开始直播","");
        if (isStart) {
            isStart = false;
            livePush.native_start("rtmp://live-push.bilivideo.com/live-bvc/?streamname=live_299750326_71525520&key=5a1885393decb1023be8f2948cb4a3cf&schedule=rtmp&pflag=1");
        }else  {
            Log.e("开始直播 jixugdkasdgakdgku","");
        }
    }
}